﻿Public Class ZeroHeightPanel
    Inherits Panel

    Protected Overrides Function MeasureOverride(s As Size) As Size
        Dim measureSize As New Size(s.Width, Double.PositiveInfinity)
        For Each u In Children.Cast(Of UIElement)()
            u.Measure(measureSize)
        Next
        Return If(Double.IsInfinity(s.Width), _
                  New Size(Children.Cast(Of UIElement).Max(Function(u) u.DesiredSize.Width), 0), _
                  New Size(s.Width, 0))
    End Function

    Protected Overrides Function ArrangeOverride(s As Size) As Size
        For Each u In Children.Cast(Of UIElement)()
            u.Arrange(New Rect(New Point(0, -u.DesiredSize.Height / 2), New Size(s.Width, u.DesiredSize.Height)))
        Next
        Return s
    End Function

End Class
